from django.db import models
from django.db import connection
    
        
class ProjectManagerCommentsManager(models.Manager):
    def get_query_set(self):
        return super(ProjectManagerCommentsManager, self).get_query_set()

    def insert_comments(self, manager_id, time_number, time_id_dict, comments_dict):
        cursor = connection.cursor()
        comments = u''
        comments_list = []
        for index in xrange(time_number):
            time_id = time_id_dict[unicode(index)]
            time_comments = comments_dict[unicode(time_id)]
            if time_comments!= u'':
                time_comments = "(" + unicode(manager_id) + ", " + unicode(time_id) + ", '" + time_comments + "')"
                comments_list.append(time_comments)
        for index in xrange(len(comments_list)):
            comments+= comments_list[index]
            if index< len(comments_list)-1:
                comments+= ', '
        if len(comments_list)!= 0:
            require =   """
                            INSERT INTO manager_projectmanagercomments 
                                (manager_id, time_id, comments)
                            VALUES """ + comments + """;
                        """
            cursor.execute(require)




